package edu.ccut.titan.tag.chart;

import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspTag;

import edu.ccut.titan.tag.AbstractBaseTag;
import edu.ccut.titan.tag.chart.utils.SubAixs;

public class TitanAixsTag extends AbstractBaseTag {

	private static final long serialVersionUID = 2897236252240948600L;

	private static final String SUB_AIXS_TAG = "sub_aixs_tag";

	private String name;

	private String color = "BLACK";

	private Object value;

	public TitanAixsTag() {
		super(SUB_AIXS_TAG);
	}

	@Override
	public int doStartTag() throws JspException {
		JspTag tag = this.getParent();
		if (tag instanceof TitanChartTag) {
			((TitanChartTag) tag).getSubAixses().add(this.getSubAixs());
		}
		
		return SKIP_BODY;
	}
	
	public int doEndTag() throws JspException {
		return SKIP_BODY;
	}

	@SuppressWarnings("unchecked")
	private SubAixs getSubAixs() {
		SubAixs aixs = new SubAixs();
		
		aixs.setName(this.name);
		aixs.setColor(this.color);
		if (this.value instanceof List) {
			aixs.setDatas((List<List<?>>)this.value);
		}
		
		return aixs;
	}

	public Object getValue() {
		return value;
	}

	public void setValue(Object value) {
		if (value instanceof String) {
			this.value = super.getExpressValueObject((String) value);
		} else {
			this.value = value;
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}
}
